package com.example.client;

import com.example.annotation.Component;

/**
 * ClassName:ReflectAnnotationTest1
 * Package:com.example.client
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/5/9-20:32
 * @Version:v1.0
 */
public class ReflectAnnotationTest1 {
    public static void main(String[] args) throws ClassNotFoundException {
        //通过反射机制读取注解
        Class<?> aClass = Class.forName("com.example.bean.User");
        //判断类上面有没有这个注解
        boolean present = aClass.isAnnotationPresent(Component.class);
        if (present){
            //获取该注解
            Component annotation = aClass.getAnnotation(Component.class);
            //访问注解属性
            String value = annotation.value();
            System.out.println(value);
        }
    }
}
